home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
Common
/
ZInvariant.cpp
< prev
next >
Wrap
Text File
|
1997-06-18
|
2KB
|
93 lines
/*
* File: ZInvariant.cpp
* Summary: Mixin for objects that use PRECONDITION and POSTCONDITION macros.
* Written by: Jesse Jones
*
* Copyright ゥ 1997 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <1> 6/14/97 JDJ Created.
*/
#include <ZInvariant.h>
#include <ZDebug.h>
#if DEBUG
// ===================================================================================
// class ZCheckInvariant
// ===================================================================================
//---------------------------------------------------------------
//
// ZCheckInvariant::~ZCheckInvariant
//
//---------------------------------------------------------------
ZCheckInvariant::~ZCheckInvariant()
{
if (mObject->mNesting == 1)
mObject->Invariant();
mObject->mNesting--;
}
//---------------------------------------------------------------
//
// ZCheckInvariant::ZCheckInvariant
//
//---------------------------------------------------------------
ZCheckInvariant::ZCheckInvariant(const MInvariant* object)
{
mObject = object;
mObject->mNesting++;
if (mObject->mNesting == 1)
mObject->Invariant();
}
#pragma mark -
// ===================================================================================
// class MInvariant
// ===================================================================================
//---------------------------------------------------------------
//
// MInvariant::~MInvariant
//
//---------------------------------------------------------------
MInvariant::~MInvariant()
{
}
//---------------------------------------------------------------
//
// MInvariant::MInvariant
//
//---------------------------------------------------------------
MInvariant::MInvariant()
{
mNesting = 0;
}
//---------------------------------------------------------------
//
// MInvariant::Invariant
//
//---------------------------------------------------------------
void MInvariant::Invariant() const
{
ASSERT(this != nil); // should never fire (if it does the vtable will be garbage amd how did we get here?)
ASSERT((long) this % 4 == 0); // should never fire
ASSERT(mNesting == 1); // possibly too strict: prevents people from calling Invariant directly
}
#endif // DEBUG